package com.daocao.ds.util;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.daocao.ds.adapter.HomeOrderAdapter;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by xsooy-pc on 18-11-19.
 */

public class SelectTimeUtil {


    public static OptionsPickerView getTimeView(Context context, DialogDefaultClickListener listener) {


        Calendar mCalendar = Calendar.getInstance();
        mCalendar.setTimeInMillis(new Date().getTime());


        List<String> options1Items = new ArrayList<String>();
        int year = mCalendar.get(Calendar.YEAR);

        for (int i = year; i >= 2017; i--) {
            options1Items.add(i + "年");
        }

        int month = mCalendar.get(Calendar.MONTH);
        List<String> data2_common = new ArrayList<>();

        for (int i = 0; i < 12; i++) {
            data2_common.add((i + 1) + "月");
        }

        List<String> data2 = new ArrayList<>();
        for (int i = 0; i <= month; i++) {
            data2.add((i + 1) + "月");
        }


        List<List<String>> options2Items = new ArrayList<>();
        for (int i = 0; i < options1Items.size(); i++) {
            if (i == 0) {
                options2Items.add(data2);
            } else {
                options2Items.add(data2_common);
            }
        }
        OptionsPickerView optionsPickerView = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
                //返回的分别是三个级别的选中位置
                if (listener != null) {
                    String two = options2Items.get(options1).get(option2).replace("月", "");
                    if (two.length() == 1) {
                        two = "0" + two;
                    }
                    listener.confirm(options1Items.get(options1).replace("年", ""), two);
                }
            }
        }).setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
            @Override
            public void onOptionsSelectChanged(int options1, int options2, int options3) {
            }
        })
                .setSubmitText("确认")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setTitleText("选择月份")//标题
                .setSubCalSize(15)//确定和取消文字大小
                .setTitleSize(17)//标题文字大小
                .setTitleColor(0xff000000)//标题文字颜色
                .setSubmitColor(0xff0072FF)//确定按钮文字颜色
                .setCancelColor(0xff0072FF)//取消按钮文字颜色
                .setTitleBgColor(0xFFF8FBFF)//标题背景颜色 Night mode
                .setBgColor(0xFFF8FBFF)//滚轮背景颜色 Night mode
                .setContentTextSize(18)//滚轮文字大小
//                .setLabels("省", "市", "区")//设置选择的三级单位
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setCyclic(false, false, false)//循环与否
                .setSelectOptions(0, 0)  //设置默认选中项
                .setOutSideCancelable(false)//点击外部dismiss default true
                .isDialog(false)//是否显示为对话框样式
                .isRestoreItem(true)//切换时是否还原，设置默认选中第一项。
                .build();
        optionsPickerView.setPicker(options1Items, options2Items);//添加数据源
        return optionsPickerView;
    }


    public interface DialogDefaultClickListener {
        public abstract void confirm(String year, String month);

    }
}
